﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectWebNhac.DTO;
using ProjectWebNhac.BUS;
using System.Data;

namespace ProjectWebNhac.GUI.User
{
    public partial class BaiHatCuaToi : System.Web.UI.Page
    {
        NguoiDungDTO nddto = new NguoiDungDTO();
        BaiHatBus bhbus = new BaiHatBus();
        CaSiBus csbus = new CaSiBus();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                loadtrang();
            }
        }

        private void loadtrang()
        {
            nddto = (NguoiDungDTO)Session["ThanhVien"];
            reBaiHat.DataSource = bhbus.LoadDanhSachBaiHatTheoUser(nddto.TaiKhoan);
            reBaiHat.DataBind();


        }

        protected void reBaiHat_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            RepeaterItem item = e.Item;
            int MaBaiHat;
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView usrCurrent = e.Item.DataItem as DataRowView;
                MaBaiHat = Convert.ToInt16(usrCurrent["MaBaiHat"]);
                Repeater reDSCaSiBaiHat = (Repeater)e.Item.FindControl("reDSCaSiBaiHat");
                reDSCaSiBaiHat.DataSource = csbus.LayCaSiTheoBaiHatTable(MaBaiHat);
                reDSCaSiBaiHat.DataBind();
            }
        }

        protected void reBaiHat_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if(e.CommandName=="Xoa")
            {
                int MaBaiHat = int.Parse(e.CommandArgument.ToString());
                bhbus.XoaBai(MaBaiHat);
                loadtrang();
            }
        }
    }
}